package top.dancun.easbaseinfo.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import top.dancun.common.utils.DataUtils;
import top.dancun.easbaseinfo.entity.RoomEntity;
import top.dancun.easbaseinfo.service.RoomService;
import top.dancun.common.utils.PageUtils;
import top.dancun.common.utils.R;
import top.dancun.easbaseinfo.vo.RoomVo;


/**
 * 
 *
 * @author dancun
 * @email message@dancun.top
 * @date 2022-10-21 16:10:50
 */
@RestController
@RequestMapping("/room")
public class RoomController {
    @Autowired
    private RoomService roomService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("easbaseinfo:room:list")
    public R list(@RequestParam Map<String, Object> params){
        Map<String,String> data = DataUtils.mapAddNoEmpty(params,RoomVo.class);
        PageUtils page = roomService.queryPage(params,data);

        return R.ok().put("page", page);
    }

    /**
     * 宿舍列表
     */
    @RequestMapping("/listdormitory")
    @RequiresPermissions("easbaseinfo:room:list")
    public R listDormitory(@RequestParam Map<String, Object> params){
        Map<String,String> data = DataUtils.mapAddNoEmpty(params, RoomVo.class);
        PageUtils page = roomService.listDormitory(params,data);

        return R.ok().put("page", page);
    }

    /**
     * 教室列表
     */
    @RequestMapping("/listclassroom")
    @RequiresPermissions("easbaseinfo:room:list")
    public R listClassRoom(@RequestBody Map<String, Object> params){
        Map<String,String> data = DataUtils.mapAddNoEmpty(params,RoomVo.class);
        PageUtils page = roomService.listClassroom(params,data);

        return R.ok().put("page", page);
    }

    /**
     * 不分页查询所有教室
     * @param params
     * @return
     */
    @RequestMapping("/listclassroomnopage")
    @RequiresPermissions("easbaseinfo:room:list")
    public R listClassRoomNoPage(@RequestBody Map<String, Object> params){
        Map<String,String> data = DataUtils.mapAddNoEmpty(params,RoomVo.class);
        List<RoomEntity> list = roomService.listClassroomNoPage(data);

        return R.ok().put("data", list);
    }

    /**
     * 楼栋列表
     */
    @RequestMapping("/listbuild")
    @RequiresPermissions("easbaseinfo:room:list")
    public R listbuilder(){
        return R.ok().put("data", roomService.listBuild());
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("easbaseinfo:room:info")
    public R info(@PathVariable("id") Integer id){
		RoomEntity room = roomService.getById(id);

        return R.ok().put("room", room);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("easbaseinfo:room:save")
    public R save(@RequestBody RoomEntity room){
		roomService.save(room);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("easbaseinfo:room:update")
    public R update(@RequestBody RoomEntity room){
		roomService.updateById(room);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("easbaseinfo:room:delete")
    public R delete(@RequestBody Integer[] ids){
		roomService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     *
     * @param ids
     * @return
     */
    @RequestMapping("/getroombyids")
    public R listRoomByIds(@RequestBody List<Integer> ids){

        List<RoomEntity> list = roomService.listRoomByIds(ids);

        return R.ok().put("data", list);
    }

}
